package xixirupan.tmgp.tencent.com.vmeim.login.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;
import xixirupan.tmgp.tencent.com.vmeim.R;

public class CompleteRegistorActivity extends AppCompatActivity {

    @BindView(R.id.complete_goback)
    ImageView completeGoback;
    @BindView(R.id.code_input)
    EditText codeInput;
    @BindView(R.id.editText_setpsw)
    EditText editTextSetpsw;
    @BindView(R.id.stateofcode)
    TextView stateofcode;
    @BindView(R.id.button_coplete)
    Button buttonCoplete;
    @BindView(R.id.sound_code)
    TextView soundCode;
    @BindView(R.id.top_)
    RelativeLayout top;
    @BindView(R.id.xian)
    TextView xian;
    @BindView(R.id.textView_phonenum)
    TextView textViewPhonenum;
    @BindView(R.id.textView_infoh)
    TextView textViewInfoh;
    @BindView(R.id.activity_complete_registor)
    RelativeLayout activityCompleteRegistor;
    private Unbinder bind;
    private String   phonenum;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_complete_registor);
        bind = ButterKnife.bind(this);
        context =this;
        Intent intent = getIntent();
         phonenum = intent.getStringExtra("phonenum");
        textViewPhonenum.setText(phonenum);

        //倒计时提示信息
      //  textViewInfoh.setText("");


    }

    @OnClick({R.id.complete_goback, R.id.stateofcode, R.id.button_coplete, R.id.sound_code})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.complete_goback:

                finish();
                break;
            //状态
            case R.id.stateofcode:

                break;
            case R.id.button_coplete:
                //成功之后转到登录界面
                //不成功转到注册界面
                String rcode = codeInput.getText() + "";
                String setPsw = editTextSetpsw.getText()+"";
                if (setPsw!=null)
                {
                    //15201226559
                    BmobUser user =new BmobUser();
                    user.setMobilePhoneNumber(phonenum);
                    user.setPassword(setPsw);
                    Log.i(";;;;;;","--"+phonenum+";;"+setPsw);
                    user.signOrLogin(rcode, new SaveListener<BmobUser>() {
                        @Override
                        public void done(BmobUser user, BmobException e) {
                                if (e == null)
                                {
                                    Log.i("TAG","---->注册或者登录成功");
                                    //转到登录页面
                                        Intent intent =new Intent(context,LoginSucessActivity.class);
                                        intent.putExtra("account",phonenum);
                                        startActivity(intent);
                                }else {
                                    Log.i("TAG","_-------->注册失败原因"+e.getMessage());
                                }
                        }
                    });
                }
                break;
            case R.id.sound_code:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
